module.exports = {
  preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
  
  // 转换忽略模式 - 包含更多需要转换的模块
  transformIgnorePatterns: [
    '/node_modules/(?!@ionic/vue|@ionic/vue-router|@ionic/core|@stencil/core|ionicons|@capacitor|@awesome-cordova-plugins)'
  ],
  
  // 测试环境配置
  testEnvironment: 'jsdom',
  testEnvironmentOptions: {
    customExportConditions: ['node', 'node-addons']
  },
  
  // 模块名称映射
  moduleNameMapping: {
    '^@/(.*)
: '<rootDir>/src/$1',
    '^@tests/(.*)
: '<rootDir>/tests/$1'
  },
  
  // 设置文件
  setupFilesAfterEnv: [
    '<rootDir>/tests/unit/setup.ts'
  ],
  
  // 覆盖率配置
  collectCoverage: true,
  collectCoverageFrom: [
    'src/**/*.{js,ts,vue}',
    '!src/main.ts',
    '!src/sw.js',
    '!src/**/*.d.ts',
    '!src/router/index.ts',
    '!**/node_modules/**'
  ],
  coverageDirectory: 'coverage',
  coverageReporters: [
    'text',
    'text-summary',
    'html',
    'lcov',
    'json'
  ],
  coverageThreshold: {
    global: {
      branches: 70,
      functions: 80,
      lines: 80,
      statements: 80
    },
    './src/components/': {
      branches: 80,
      functions: 90,
      lines: 90,
      statements: 90
    },
    './src/composables/': {
      branches: 75,
      functions: 85,
      lines: 85,
      statements: 85
    }
  },
  
  // 测试文件匹配模式
  testMatch: [
    '<rootDir>/tests/unit/**/*.spec.{js,ts}',
    '<rootDir>/src/**/__tests__/*.{js,ts}',
    '<rootDir>/src/**/*.test.{js,ts}'
  ],
  
  // 全局变量
  globals: {
    'ts-jest': {
      useESM: true
    },
    // HarmonyOS 环境模拟
    'window.HarmonyOS': true,
    'window.HarmonyBridge': {}
  },
  
  // 模拟文件
  moduleFileExtensions: [
    'js',
    'ts',
    'json',
    'vue'
  ],
  
  // 清除模拟
  clearMocks: true,
  restoreMocks: true,
  
  // 测试超时
  testTimeout: 10000,
  
  // 详细输出
  verbose: true,
  
  // 错误时停止
  bail: false,
  
  // 并行测试
  maxWorkers: '50%'
}
